package com.example.prison.mapper;

import com.example.prison.entity.CarAlarmRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【car_alarm_record】的数据库操作Mapper
* @createDate 2024-06-03 14:17:45
* @Entity com.example.prison.entity.CarAlarmRecord
*/
@Mapper
public interface CarAlarmRecordMapper extends BaseMapper<CarAlarmRecord> {

    @Select("<script>select * from car_alarm_record " +
            " <where> " +
            " <if test=\"carNumber != null and carNumber != ''\">and car_number like concat('%',#{carNumber},'%') </if> " +
            " <if test=\"beginTime != null and beginTime != ''\">and appointment_time &gt;= #{beginTime} </if> " +
            " <if test=\"endTime != null and endTime != ''\">and appointment_time &lt;= #{endTime} </if> " +
            " </where> " +
            "order by id desc</script>")
    List<CarAlarmRecord> get(@Param("carNumber")String carNumber, @Param("beginTime") String beginTime, @Param("endTime")String endTime);

    @Insert("insert into car_alarm_record(type,time,car_number,use_people,note,solve,handle,handle_message) " +
            "values (#{type},#{time},#{carNumber},#{usePeople},#{note},#{solve},#{handle},#{handleMessage})")
    int add(CarAlarmRecord record);

    @Delete("<script>delete from car_alarm_record where id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleting(@Param("ids") Integer[] ids);

    @Update("update car_alarm_record set solve='已处理',handle=#{handle},handle_message=#{handleMessage} where id = #{id}")
    int handle(@Param("id")Integer id, @Param("handle")String handle, @Param("handleMessage")String handleMessage);

    @Select("select * from car_alarm_record where id=#{id}")
    CarAlarmRecord getById(@Param("id") Integer id);

    @Select("select * from car_alarm_record where car_number=#{carNumber} and solve='未处理'")
    CarAlarmRecord getOneNoReturnByCarNumber(@Param("carNumber") String carNumber);


}




